<?php
require_once 'function.php';

/*翻转reverse*/
// $target = $argv[1];
// $arr = [0,1,2,3,4,5,6,7,8];
// $arr = reverse($arr);
// print_r($arr);

/******************************************************************/

/*插入insert*/
// $arr = [1,2,3,4,5,6,7,8,9,10];
// $flag = insert($arr, 5, 'hxm');
// if ($flag) {
// 	echo '插入成功' . PHP_EOL;
// 	print_r($arr);
// }else echo '插入失败' . PHP_EOL;

/******************************************************************/

/*插入排序insert_sort*/
// $arr = [55,6,8,20,684,68,13,69,856,789,147,258,369,753,159,100];
// $sorted = insert_sort($arr);
// print_r($sorted);

/******************************************************************/

/*二分查找binary_search*/
$arr = [55,6,8,20,684,68,13,69,856,789,147,258,369,753,159,100];
$sorted = insert_sort($arr);
print_r($sorted);
$flag = binary_search($sorted, 5);
if ($flag == -1) {
	echo 'The target is not in this array!';
	}else echo '该数在此数组的下标为：' . $flag;